package com.kcwoo.shaokun.rxjavalearning

import android.app.ActivityManager
import android.app.Application
import android.content.Context
import android.util.Log


/**
 * Created by kevin on 2017/11/8.
 *  step one small every day
 */
class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        val pid = android.os.Process.myPid()
        Log.d("akun", "pName  $pid")
        val pName = getProcessName(this, pid)
        Log.d("akun", "pName  $pName")
    }

    fun getProcessName(cxt: Context, pid: Int): String? {
        val am = cxt.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        val runningApps = am.runningAppProcesses ?: return null
        return runningApps
                .firstOrNull { it.pid == pid }
                ?.processName
    }
}